package com.evil.application.listener;

import com.evil.application.annotation.Automation;
import com.evil.application.service.RobotActionService;
import com.evil.common.application.dto.mq.RobotActionMQReqDTO;
import com.evil.common.rocketmq.constant.MQConstant;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 应用机器人 队列消费着
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@Component
@AllArgsConstructor
@RocketMQMessageListener(
        topic = MQConstant.APPLICATION_ROBOT_MQ_KEY,
        consumerGroup = MQConstant.APPLICATION_ROBOT_CONSUMER_GROUP
)
public class AppRobotRocketMqConsumer implements RocketMQListener<RobotActionMQReqDTO> {

    private final RobotActionService robotActionService;

    @Override
    @Automation
    public void onMessage(@Validated RobotActionMQReqDTO robotActionMQReqDTO) {
        log.info("Receive application robot message：orderId:{}, triggerType:{}", robotActionMQReqDTO.getOrderId(), robotActionMQReqDTO.getTriggerType());
        log.info("【应用机器人队列消费者】，logAppKeys数量：{}", robotActionMQReqDTO.getLogAppKeys().size());

        robotActionService.robotActionErrorHandle(robotActionMQReqDTO);
    }
}
